package cn.itcast.service.impl;

import cn.itcast.dao.AddressDao;
import cn.itcast.pojo.Address;
import cn.itcast.service.AddressService;
import com.alibaba.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@Service(version = "1.0.0")
public class AddressServiceImpl implements AddressService {

    @Autowired
    private AddressDao addressDao;


    /*
        新增Address数据
     */
    @Override
    public void addAddress(Address address) {
        addressDao.add(address);
    }


    /*
        查询Address数据
    */
    public List<Address> findAll(){
        return  addressDao.findAll();
    }

    /*
        编辑Address数据
    */
    @Override
    public void update(Address address) {
        addressDao.update(address);
    }

    /**
     * 根据id查Address数据
     * @param id
     * @return
     */
    @Override
    public Address findById(Integer id) {
        return addressDao.findById(id);
    }

    /**
     * 根据Id值启动开关
     * @param id
     */
    @Override
    public void changeEnable(Integer id) {
        Address result = addressDao.findById(id);
        if(result.getEnable().equals(1)){
            result.setEnable(0);
            addressDao.update(result);
        }else {
            result.setEnable(1);
            addressDao.update(result);
        }
    }

    /**
     * 根据id删除Address数据
     * @param id
     */
    @Override
    public void delete(Integer id) {
        addressDao.delete(id);
    }


}
